﻿namespace PowerSong.SongDatabase
    {
    using System;
    using System.IO;

    public abstract class BaseEntity
        {

        /// <summary>
        /// Gets or sets the ID of this entity. When writing entities to the database, the ID is used to indicate uniqueness.
        /// To write new entities, supply new IDs, otherwise don't change the IDs loaded from the database if you wish to update entities.
        /// </summary>
        public Guid ID { get; set; }

        internal FileEntryType Type { get; private set; }

        internal int SchemaVersion { get; private set; }

        internal BaseEntity(FileEntryType type, int schemaVersion)
            {
            this.Type = type;
            this.ID = Guid.NewGuid();
            this.SchemaVersion = schemaVersion;
            }

        internal abstract bool Deserialise(Database database, BinaryReader reader, int version);

        internal abstract void Serialise(BinaryWriter writer);

        /// <summary>
        /// All entities that inherit from the BaseEntity class must provide a string representation of the entity by default.
        /// </summary>
        /// <returns>A string representation of this entity.</returns>
        public abstract override string ToString();

        }

    }
